package br.com.comanda.webservice.business;

import java.util.List;

import br.com.comanda.webservice.dao.AccountDAO;
import br.com.comanda.webservice.dao.impl.AccountDAOImpl;
import br.com.comanda.webservice.model.Account;
import br.com.comanda.webservice.model.User;
import br.com.comanda.webservice.persistence.HibernateUtil;

public class AccountBusiness {

	public List<Account> findAll() {
		AccountDAOImpl dao = new AccountDAOImpl();
		dao.setSession(HibernateUtil.getSession());
		return dao.findOpenAccounts();
	}

	public void save(Account account) {
		AccountDAO dao = new AccountDAOImpl();
		dao.setSession(HibernateUtil.getSession());

		User user = new User();
		user.setId(1);
		account.setUser(user);

		dao.save(account);
	}

	public void closeAccount(int accountId) {
		AccountDAOImpl dao = new AccountDAOImpl();
		dao.setSession(HibernateUtil.getSession());

		dao.closeAccount(accountId);
	}
}
